# Contributor: Ted Trask <ttrask01@yahoo.com>
# Maintainer: Ted Trask <ttrask01@yahoo.com>
_luaversions="5.1 5.2 5.3 5.4"
pkgname=lua-subprocess
pkgver=0_git20230625
pkgrel=1
_gitrev=ccd71c90653b39c6745c771af4393c9e76e4105f
pkgdesc="A Lua module written in C that allows you to create child processes and communicate with them"
url="https://github.com/tdtrask/lua-subprocess"
arch="all"
license="MIT"
makedepends="asciidoc"
for _i in $_luaversions; do
	makedepends="$makedepends lua$_i-dev"
	subpackages="$subpackages lua$_i-subprocess:_split"
done
source="$pkgname-$_gitrev.tar.gz::https://github.com/tdtrask/lua-subprocess/archive/$_gitrev.tar.gz
	makefile.patch
	gcc14.patch
	"
builddir="$srcdir/lua-subprocess-$_gitrev"
options="!check"

prepare() {
	default_prepare
	for _i in $_luaversions; do
		cp -r "$builddir" "$srcdir"/build-$_i
	done
}

build() {
	export CFLAGS="$CFLAGS -DSHARE_LIOLIB"
	for _i in $_luaversions; do
		cd "$srcdir"/build-$_i
		make lua_package="lua$_i"
	done
}

package() {
	for _i in $_luaversions; do
		cd "$srcdir"/build-$_i
		make lua_package="lua$_i" DESTDIR="$pkgdir" install
	done
}

_split() {
	local d= _ver=${subpkgname%%-*}
	_ver=${_ver#lua}
	pkgdesc="A Lua $_ver module written in C that allows you to create child processes and communicate with them"
	install_if="lua$_ver $pkgname=$pkgver-r$pkgrel"
	for d in usr/lib/lua usr/share/lua; do
		if [ -d "$pkgdir"/$d/$_ver ]; then
			mkdir -p "$subpkgdir"/$d
			mv "$pkgdir"/$d/$_ver "$subpkgdir"/$d/
		fi
	done
}

sha512sums="
d6c2cb45225f518748405ae6039ecad5475eac029f1a1f7250a73dcfcc429420298884d00f8d11677b3fffab833232d3b9436a067cfcce8f70585b2a2b31c46e  lua-subprocess-ccd71c90653b39c6745c771af4393c9e76e4105f.tar.gz
af4e25d8d503e9cb8296a2b8d8b19577e64b412f56607bf38bc828a7c214904ecdf9619fc2541461bc4dda6c6fcd47cbb1051499bd2f132dad76092cf3ae5e9d  makefile.patch
0ce34bd5068be6a64b488c4f11d69852449e1d44adb12e5a78327582eb6c60ce8eb977d63b4fb2b4b87a44e74f232cfa2904f02f84623a39dda0cd8674dfa093  gcc14.patch
"
